package ReflectionTest;

class Person {
    static int worker_uid = 100;
    final static int final_worker_uid = 100;

    static {
        System.out.println("static worker_uid: " + worker_uid);
        worker_uid = 200;
        System.out.println("Person static block set worker_uid: " + worker_uid);
    }

    Person() {
        worker_uid = 300;
        System.out.println("Person constructor set worker_uid: " + worker_uid);
    }

    {
        System.out.println("Person block set worker_uid: " + worker_uid);
        worker_uid = 400;
    }
}

class Worker extends User {
    static {
        System.out.println("static worker_uid: " + worker_uid);
        worker_uid = 200;
        System.out.println("Worker static block set worker_uid: " + worker_uid);
    }

    Worker() {
        worker_uid = 300;
        System.out.println("Worker constructor set worker_uid: " + worker_uid);
    }

    {
        System.out.println("Worker block set worker_uid: " + worker_uid);
        worker_uid = 400;
    }
}

public class ClassLoadTest {
    public static void main(String[] args) {
        // 触发类的初始化
        // System.out.println(new Person());

        // 访问静态字段不是真正声明在该类中的，不会触发类的初始化
        // System.out.println(Worker.worker_uid);

        // 通过子类引用父类的静态字段，不会触发子类的初始化
        // System.out.println(Worker.worker_uid);

        // 仅声明Worker数组，不会触发Worker类的初始化
        // System.out.println(new Worker[10]);

        // 引用常量不会触发类的初始化
        // System.out.println(Worker.final_worker_uid);
    }
}
